/* eslint-disable indent */
import { connect } from 'dva';
import React, { Component } from 'react';
import { Table, Pagination, Popconfirm, Button } from 'antd';
import ${className}EditForm from './${className}EditForm';

const ${className}List  = ({page,selectedRowKeys,loading,dispatch}) =>{
    // 处理列表选择框
    const rowSelection = {
        selectedRowKeys,
        onChange: (selectedRowKeys)=>{
            dispatch({
                type: '${classObjectName}/rowSelection',
                payload: {selectedRowKeys}
            });
        }
    };
    // 处理分页数据
    const handlePageChange = (pageNum,pageSize) =>{
        dispatch({
            type: '${classObjectName}/getPages',
            payload: {pageNum,pageSize}
        });
    };

    const handleModelShow = (id) =>{
        dispatch({type: '${classObjectName}/detail',payload:{id}});
        dispatch({type: '${classObjectName}/handleEditModelState',payload:{editVisible:true}});
    };

    const columns = [
<#list fields as field>
    <#if field.fieldName != keyName>
        { title: '${field.remarks}', dataIndex: '${field.fieldName}', key: '${field.fieldName}', }<#if field_has_next>,</#if>
    </#if>
</#list>
    ];

    const body = (
        <div>
            <${className}EditForm/>
            <Table rowSelection={rowSelection} columns={columns} dataSource={page.pageData} rowKey={record => record.id} loading={loading} pagination={false}/>
            <div>
                <Pagination total={page.total} current={page.pageNum} pageSize={page.pageSize} onChange={handlePageChange}
                            onShowSizeChange={(current,pageSize)=>handlePageChange(current,pageSize)}
                    showTotal={(total, range) => `共${r'${total}'} 条数据,当前展示第:${r'${range[0]}'}-${r'${range[1]}'} 条`}
                    showSizeChanger showQuickJumper/>
            </div>
        </div>
    );

    return body ;
};

function mapStateToProps(state) {
    const {page,selectedRowKeys} = state.${classObjectName};
    return { loading: state.loading.models.${classObjectName}, page, selectedRowKeys };
}

export default connect(mapStateToProps)(${className}List);
